using System.Security.Principal;
using System.Threading;

namespace TaskKernel.Domain.Services.Action
{
    public class TaskServiceByRole : ITaskService
    {
        private readonly ITaskAction _taskAction;

        public TaskServiceByRole(ITaskAction taskAction, RoleEnum role)
        {
            _taskAction = taskAction;
            Role = role;
        }
        public RoleEnum Role { get; protected set; }

        public void ChangePrincipal()
        {
            var wIdent = WindowsIdentity.GetCurrent();
            var customPrincipal = new CustomPrincipal(wIdent, Role);
            Thread.CurrentPrincipal = customPrincipal;
        }
        public ITaskAction GetAction()
        {
            ChangePrincipal();
            return _taskAction;
        }
    }
}